package com.ckzp.jfinal.system.util;

import com.ckzp.core.util.StringUtil;
import com.ckzp.jfinal.interceptor.AuthActivity;
import com.ckzp.jfinal.system.cache.SysRoleCache;
import com.ckzp.jfinal.system.cache.SysUserCache;
import com.ckzp.jfinal.system.model.SysActivity;

/**
 * Created by 51594 on 2022/8/5.
 */
public class SysActivityUtil {

    public static SysActivityUtil n() {
        return new SysActivityUtil();
    }


    /**
     * @param am
     */
    public AuthActivity saveSysActivity(AuthActivity am) {
        am.setAct_role(StringUtil.replace(am.getAct_role(), ",", "|"));
        SysActivity act = SysActivity.dao.findFirst("select * from sys_activity where act_path=?", am.getAct_path());
        if (act == null) {
            String act_role_name = SysRoleCache.transRoleName(am.getAct_role());
            String act_user_name = SysUserCache.transUserName(am.getAct_user());
            new SysActivity()
                    .set("act_name", am.getAct_name())
                    .set("act_path", am.getAct_path())
                    .set("act_role", am.getAct_role())
                    .set("act_role_name", act_role_name)
                    .set("act_user", am.getAct_user())
                    .set("act_user_name",act_user_name)
                    .set("is_log", am.isIs_log())
                    .save();
        }
        return am;
    }
}
